#define _CRT_SECURE_NO_WARNINGS 1
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{
    struct ListNode* guard, * Ptail;
    guard = Ptail = (struct ListNode*)malloc(sizeof(struct ListNode));
    if (guard == NULL)
    {
        perror("malloc fail");
        exit(1);
    }
    guard->next = NULL;
    while (list1 != NULL && list2 != NULL)
    {
        if (list1->val > list2->val)
        {
            Ptail->next = list2;
            Ptail = Ptail->next;
            list2 = list2->next;
        }
        else
        {
            Ptail->next = list1;
            Ptail = Ptail->next;
            list1 = list1->next;
        }
    }
    if (list1 != NULL)
        Ptail->next = list1;
    if (list2 != NULL)
        Ptail->next = list2;
    struct ListNode* NewHead = guard->next;
    free(guard);
    return NewHead;
}
